package com.sc.passbook.mapper;

import com.sc.passbook.constant.Constant;
import com.sc.passbook.vo.Pass;
import com.spring4all.spring.boot.starter.hbase.api.RowMapper;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;

/**
 * @author sc
 * Created on  2018/9/1
 */

public class PassMapper implements RowMapper<Pass>{

    private static byte[] FAMILY_I = Constant.PassTable.FAMILY_I.getBytes();
    private static byte[] USER_ID = Constant.PassTable.USER_ID.getBytes();
    private static byte[] TOKEN = Constant.PassTable.TOKEN.getBytes();
    private static byte[] TEMPLATE_ID = Constant.PassTable.TEMPLATE_ID.getBytes();
    private static byte[] ASSIGNED_DATE = Constant.PassTable.ASSIGNED_DATE.getBytes();
    private static byte[] CON_DATE = Constant.PassTable.CONSUME_DATE.getBytes();
    @Override
    public Pass mapRow(Result result, int i) throws Exception {
        Pass pass = new Pass(
                Bytes.toString(null),
                Bytes.toLong(result.getValue(FAMILY_I,USER_ID)),
                Bytes.toString(result.getValue(FAMILY_I,TEMPLATE_ID)),
                Bytes.toString(result.getValue(FAMILY_I,TOKEN)),
                DateUtils.parseDate(Bytes.toString(result.getValue(FAMILY_I,ASSIGNED_DATE))),
                DateUtils.parseDate(Bytes.toString(result.getValue(FAMILY_I,CON_DATE)))
        );
        return pass;
    }
}
